<template>
  <div class="app-container">
    <Head :flag="true" />
    <!-- 表格 -->
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
        :header-cell-style="{ color: '#000000', fontSize: '15px' }"
      >
        <el-table-column type="selection" align="center"> </el-table-column>
        <el-table-column prop="server_name" label="服务器名称" align="center">
        </el-table-column>
        <el-table-column prop="level" label="分级类别" align="center">
        </el-table-column>
        <el-table-column prop="" label="是否显示" align="center">
          <template slot-scope="scope">
            <el-switch
              :value="scope.row.is_show === 1 ? true : false"
              active-color="#13ce66"
              inactive-color="#DCE0E7"
              @change="change(scope.$index, scope.row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="sort" label="排序" align="center">
        </el-table-column>
        <el-table-column prop="does" label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button type="danger" @click="handleDel(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageIndex"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import Head from "@/components/type_header";
import pagination from "@/components/Pagination";
import { getLastType } from "@/api/news";
export default {
  components: {
    Head,
    pagination, //分页
  },
  data() {
    return {
      listLoading: false,
      total: 0,
      listQuery: {
        pageIndex: 1,
        pageSize: 10,
      },
      tableData: [],

      multipleSelection: [],
    };
  },
  created() {
    //分页
    this.getList();
    if (this.$route.params.id === undefined) {
      let id = localStorage.getItem("id");
      let aid = Number(localStorage.getItem("aid"));
      getLastType({ id: id, aid: aid }).then((res) => {
        if (res.code === 200) {
          this.tableData = res.data;
          this.total = this.tableData.length;
        }
      });
    } else {
      localStorage.setItem("id", this.$route.params.id);
      localStorage.setItem("aid", this.$route.params.aid);
      getLastType(this.$route.params).then((res) => {
        if (res.code === 200) {
          this.tableData = res.data;
          this.total = this.tableData.length;
        }
      });
    }
  },
  methods: {
    //分页
    getList(val) {
      console.log(val);
      this.listLoading = true;

      this.listLoading = false;
    },
    //开关
    change(index, val) {
      val.is_show = val.is_show === 1 ? 2 : 1;
      console.log(index, val);
    },
    //编辑
    handleEdit(index, val) {
      console.log(index, val);
      this.$router.push('/commodity_manager/typeEdit')
    },
    //删除
    handleDel(index, val) {
      console.log(index, val);
    },
    //批量删除
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(val);
    },
  },
};
</script>

<style scoped lang="scss">
.table {
  width: 100%;
  margin: 0 auto;
  margin-top: 30px;
  min-width: 1200px;
}
</style>
